package com.kindergarten.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kindergarten.pojo.Sign;
import com.kindergarten.service.ISignService;
import com.kindergarten.service.IUserService;
import com.kindergarten.utils.MMGridPageVoBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/parent-sign-api")
public class ParentSignController {


    @Autowired
    ISignService signService;

    @Autowired
    IUserService iUserService;

    /**
     * 01-跳转到模板引擎页面
     *
     * @return
     */
    @GetMapping("topage")
    public String topage() {
        return "childSign";
    }

    /**
     * 02-数据加载分页
     * @return
     */
    @ResponseBody
    @RequestMapping("childsign")
    public MMGridPageVoBean page(Sign sign) {
        MMGridPageVoBean pageVoBean = new MMGridPageVoBean();

        sign.setPage((sign.getPage()-1)*sign.getLimit()); //开始查询的位置
        List<Sign> signList = signService.getAllChildSignByLimit(sign);
        for (Sign s : signList) {
            String kqrId = s.getKqrId();
            s.setUserName(iUserService.getById(kqrId).getUserName());
        }
        pageVoBean.setRows(signList); //每页数据

        int total = signService.countAllChildSignByLimit(sign);
        pageVoBean.setTotal(total); //总条数
        return pageVoBean;
    }

}
